home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000138_icon-group-sender _Thu Jun 12 17:53:32 1997.msg < prev   
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: from kingfisher.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 16 Jun 1997 08:43:02 MST
  2. Received: by kingfisher.CS.Arizona.EDU; (5.65v3.2/1.1.8.2/08Nov94-0446PM)
  3.     id AA10747; Mon, 16 Jun 1997 08:43:02 -0700
  4. Date: Thu, 12 Jun 1997 17:53:32 -0400
  5. Message-Id: <199706122153.RAA05260@axp.cmpu.net>
  6. Mime-Version: 1.0
  7. Content-Type: text/plain
  8. Content-Transfer-Encoding: 7bit
  9. From: gep2@computek.net
  10. Subject: Re: searching with variables
  11. To: icon-group@cs.arizona.edu
  12. X-Mailer: SPRY Mail Version: 04.00.06.17
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15. Content-Length: 1644
  16.  
  17. >> A quick question.  If you wanted to use the function find() to search for
  18.  > a particular strings of characters, how would it be possible to define
  19.  > character variables?  For example, suppose you want to search for the
  20.  > following sequences
  21.  > 
  22.  > al
  23.  > el
  24.  > il
  25.  > ol
  26.  > ul
  27.  > 
  28.  > which are really just Vl (where V stands for a vowel).  Could you simply
  29.  > define a character set for vowels (V := 'aeiou') and then refer to that
  30.  > character set in the find() function?  If so, what would it look like?  I
  31.  > tried something like the following and it didn't work.
  32.  > 
  33.  > find( V || "l")
  34.  > 
  35.  > I realise it's a pretty trivial task but I don't have the manual at the
  36.  > moment and I'd like an answer within the next couple of days.  Thanks in
  37.  > advance.
  38.  
  39. >Well you don't (want to use find()).
  40. Function find() only matches substrings.
  41.  
  42. >Try this (based on "The Icon Programming Language" (1983), p 177):
  43. procedure Vl(line)
  44.   static vowel
  45.   local line, i
  46.   initial vowel := 'aeiou'
  47.   i := 1
  48.   while i := upto(vowel,line,i) do {
  49.     suspend line[i+:2]
  50.     i += 2
  51.   }
  52. end
  53.  
  54. >procedure testVl()
  55.   local line
  56.   while line := read() do {
  57.     every write(Vl(line))
  58.   }
  59. end
  60.  
  61. This is another example of where SNOBOL4/SPITBOL is easier and simpler and more 
  62. direct than Icon.
  63.  
  64. In SNOBOL4 one can simply use:
  65.  
  66.          &TRIM = 1
  67.          PAT = FENCE (BREAKX("aeiou") LEN(1) "l") $ OUTPUT FAIL
  68. RDLOOP   LINE = INPUT                                    :F(END)
  69.          LINE PAT                                        :F(RDLOOP)
  70. END
  71.  
  72. Gordon Peterson
  73. http://www.computek.net/public/gep2/
  74. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  75.  
  76.